import logging
import cv2
import os
import numpy as np

logger = logging.getLogger(__name__)


def pic_same(path1, path2):
    """
     判断两张图片是否相同
    :param path1: 图片1的路径
    :param path2: 图片2的路径
    :return:
    """
    logger.info(f"图片一为：{path1}")
    logger.info(f"图片二为：{path2}")
    if os.path.exists(path1) and os.path.exists(path2):
        image1 = cv2.imread(path1)
        image2 = cv2.imread(path2)
        difference = cv2.subtract(image1, image2)
        differ = np.any(difference)

        if not differ:
            print("两张图片相同,测试通过")
            logger.info("两张图片相同,测试通过")
            return True
        else:
            path = 'differ.png'
            cv2.imwrite(path, difference)
            logger.error("两张图片不相同，测试不通过")
            return False
    else:
        logger.error("相比较的两张图片路径错误")
